package cn.edu.flink.scala.tutorial.wordcount

import org.apache.flink.api.scala._

//  $ bin/flink run -Dexecution.runtime-mode=BATCH BatchWordCount.jar 可以在任务提交时指定批处理，代码中的ExecutionEnvironment可替换为StreamExecutionEnvironment
object BatchWordCount {
  def main(args: Array[String]): Unit = {
    //创建执行环境并配置并行度
    val env = ExecutionEnvironment.getExecutionEnvironment

    //读取文本文件
    val lineDS = env.readTextFile("input/word.txt")
    //对数据进行格式转换
    val wordAndOne = lineDS.flatMap(_.split(" ")).map(r => (r, 1))
    //对数据进行分组
    val wordAndOneUG = wordAndOne.groupBy(0)
    //对分组数据进行聚合
    val sum = wordAndOneUG.sum(1)
    //打印结果
    sum.print

  }
}
